home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: Camelot / Camelot 043 (1989-06)(Swedish User Group of Amiga)(SE)(PD)[WB].zip / Camelot 043 (1989-06)(Swedish User Group of Amiga)(SE)(PD)[WB].adf / printfx / _main.a next >
Text File  |  1989-06-08  |  3KB  |  80 lines

  1.  
  2.  
  3. EOL    equ    $0a        CLI command activator
  4.  
  5.     xdef    __main
  6.  
  7.     csect    text,0,0,1,2    any xref's after this are 16-bit reloc
  8.  
  9.     xref    _main        Name of C program to start with.
  10.  
  11. __main:    movem.l    d2/d3/a2,-(a7)
  12.  
  13. *** insert terminators, get pointers, find argc
  14.     move.l    a7,a2        keep stackpointer
  15.     move.l    16(a7),a0    get begin
  16.     lea.l    0(a7),a1    remember first argv for reverse action
  17.     moveq.l    #0,d3        argc (program name)
  18.  
  19. SrcNSp    move.b    (a0),d0        search *argv
  20.     cmp.b    #' ',d0        spaces are delimiters
  21.     bhi.s    Found        any printable but SP causes an *argv
  22.     bcs.s    FinalT        any control causes a leave loop
  23. KillSp    clr.b    (a0)+        no spaces allowed
  24.     bra.s    SrcNSp
  25. Found    cmp.b    #'"',d0        entry embedded spaces?
  26.     beq.s    SplFnd        yes, special search action
  27.     move.l    a0,-(a7)    no, normal, push a *argv
  28.     addq.l    #1,d3        ++argc
  29. SrcSp    cmp.b    #' ',(a0)    now search for end
  30.     beq.s    KillSp        end found, search next *argv
  31.     bcs.s    FinalT        very end found; leave
  32.     addq.l    #1,a0        still inside argument,
  33.     bra.s    SrcSp        so keep searching for delimiter
  34. SplFnd    addq.l    #1,a0        skip special entry code char
  35.     move.l    a0,-(a7)    push a *argv
  36.     addq.l    #1,d3        ++argc
  37. SrcSpl    move.b    (a0),d0        only '"' and '\0' are delimiters (EOL?)
  38.     beq.s    FinalT        very end found; leave
  39.     cmp.b    #'"',d0        special delimiter?
  40.     beq.s    KillSp        yes, act like space found
  41.     cmp.b    #EOL,d0        @ we look for EOL too
  42.     beq.s    FinalT        @ and leave on meeting it
  43.     addq.l    #1,a0        no, still inside argument,
  44.     bra.s    SrcSpl        so keep searching for delimiter
  45. FinalT    clr.b    (a0)        now, here is my story:
  46.  
  47. * If the command line does not contain any embedded space arguments,
  48. * FinalTerm deletes the closing control, normally a LF. However, you are
  49. * allowed to embed all controls but '\0' in embedded space arguments. If
  50. * you do not close this argument with '"', but instead gives an EOL, this
  51. * EOL takes part of this argument. In this version, we leave the loop on
  52. * finding it. (@)
  53.  
  54. *** The argv-array is in reversed order, so do something about it
  55.     move.l    a7,a0        get begin, end is already in a1
  56.     move.l    d3,d2        get number of pointers
  57.     lsr.l    #1,d2        argc/2 we exchange two at a time
  58.     bra.s    XPtrs1
  59. XPtrs0    move.l    -(a1),d0
  60.     move.l    (a0),d1
  61.     move.l    d0,(a0)+
  62.     move.l    d1,(a1)
  63. XPtrs1    dbra    d2,XPtrs0        
  64.  
  65. *** For some reasons its nice to have a long aligned stackpointer.    
  66.     move.l    a7,d1        argv
  67.     move.l    a7,d0        prepare for long line up
  68.     lsr.l    #2,d0        we look for a carry 
  69.     bcc.s    LongAl        already long
  70.     subq.l    #2,a7        make a7 long aligned
  71. LongAl    move.l    d1,-(a7)    push *argv[]
  72.     move.l    d3,-(a7)    push argc
  73.     jsr    _main(pc)    Our main is NOT void!
  74.     move.l    a2,a7        restore stackpointer
  75.     movem.l    (a7)+,d2/d3/a2
  76.     rts
  77.     
  78.     end
  79.  
  80.